package com.blockchain.console.servlets.content.coin;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.blockchain.common.enums.IsPass;
import com.blockchain.common.enums.ZrState;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.XlbEntity;
import com.blockchain.console.service.trading.query.XlbQuery;
import com.blockchain.console.servlets.content.AbstractContentServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.http.upload.PartFile;
import com.blockchain.framework.http.upload.UploadFile;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.BigDecimalParser;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;
import com.blockchain.util.parser.TimestampParser;
@MultipartConfig
@Right(id = "C_SYS_BEDIT", isMenu = true, name = "币信息修改")
public class UpdateBInfo extends AbstractContentServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id=IntegerParser.parse(request.getParameter("id"));
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		XlbEntity x=tsradingManage.getXlb(id);
		request.setAttribute("x", x);
		forwardView(request, response, getClass());
	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		int id=IntegerParser.parse(request.getParameter("id"));
		XlbQuery query = new XlbQuery() {
			@Override
			public BigDecimal getZx_xz() {
				return BigDecimalParser.parse(request.getParameter("zc_zx"));
			}
			@Override
			public String getZwm() {
				return request.getParameter("zwm");
			}

			@Override
			public BigDecimal getZg_sxf() {
				return BigDecimalParser.parse(request.getParameter("zg_sxf"));
			}

			@Override
			public BigDecimal getZd_xz() {
				return BigDecimalParser.parse(request.getParameter("zc_zd"));
			}

			@Override
			public BigDecimal getZd_sxf() {
				return BigDecimalParser.parse(request.getParameter("zd_sxf"));
			}

			@Override
			public ZrState getZc_zr() {
				return EnumParser.parse(ZrState.class, request.getParameter("zc_zr"));
			}

			@Override
			public IsPass getZc_zc() {
				return EnumParser.parse(IsPass.class, request.getParameter("zc_zc"));
			}

			@Override
			public String getYwm() {
				return request.getParameter("ywm");
			}

			@Override
			public String getYwjc() {
				return request.getParameter("ywjc");
			}

			@Override
			public UploadFile getTblj() throws IOException, ServletException {
				Part part = request.getPart("image");
				if (part == null || part.getContentType() == null || part.getSize() == 0) {
					return null;
				}
				return new PartFile(part);
			}

			@Override
			public IsPass getSfzdzrlqb() {
				return EnumParser.parse(IsPass.class, request.getParameter("sfzdzrlqb"));
			}

			@Override
			public String getR_qbsy() {
				return request.getParameter("rqbsy");
			}

			@Override
			public String getR_qbdz() {
				return request.getParameter("rqbdz");
			}

			@Override
			public String getL_qbdz() {
				return request.getParameter("lqbdz");
			}

			@Override
			public String getDy_zdzr() {
				return request.getParameter("dy_zdzr");
			}

			@Override
			public Timestamp getCreateTimeStart() {
				return null;
			}

			@Override
			public Timestamp getCreateTimeEnd() {
				return null;
			}
			
			public String getWalletIp() {
				return request.getParameter("wallet_ip");
			}
			
			public String getWalletPort() {
				return request.getParameter("wallet_port");
			}
			
			public String getWalletUsername() {
				return request.getParameter("wallet_username");
			}
			
			public String getWalletPassword() {
				return request.getParameter("wallet_password");
			}
			@Override
			public Timestamp getTcrq() {
				return  TimestampParser.parse(request.getParameter("tcrq"));
			}
			
			public String getMethodId() {
				return request.getParameter("methodId");
			}
			@Override
			public String getContractAddress() {
				return request.getParameter("contractAddress");
			}
			@Override
			public String getUnit() {
				return request.getParameter("unit");
			}
			@Override
			public String getCoinType() {
				return request.getParameter("coin_type");
			}
			@Override
			public String getTranHotWallet() {
				return request.getParameter("tranHotWallet");
			}
			@Override
			public String getCoinNameTw() {
				return request.getParameter("coinNameTw");
			}
			@Override
			public String getCoinDesc() {
				return request.getParameter("coinDesc");
			}
			@Override
			public String getCoinDescEn() {
				return request.getParameter("coinDescEn");
			}
			@Override
			public String getCoinDescTw() {
				return request.getParameter("coinDescTw");
			}
			
		};
		tsradingManage.updateXlbInfo(query, id);
		sendRedirect(request, response, getController().getURI(request, SearchBxx.class));
	}

}
